package datasource.image;

import java.text.DateFormat;
import java.text.Format;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

import thesis.DataObject;

public class ImageObj extends DataObject {
	public Date time = null;
	Set<String> tags = new HashSet<String>();
	public String userId;
	public int timeClusterID;
	public String path;
	private HashMap<String, Double> eventTags = new HashMap<String, Double>();
	private HashMap<String, Double> concepts = new HashMap<String, Double>();
	private HashMap<String, Double> people = new HashMap<String, Double>();

	public HashMap<String, Double> getConcepts() {
		return concepts;
	}

	public HashMap<String, Double> getEventTags() {
		return eventTags;
	}

	public void addPeople(String name, double prob) {
		getPeople().put(name, prob);
	}

	public void setEventTags(HashMap<String, Double> eventTags) {
		this.eventTags = eventTags;
	}

	public void addEventTag(String tag, double prob) {
		eventTags.put(tag, prob);
	}

	public void addConcept(String concept, double prob) {
		concepts.put(concept, prob);
	}

	public ImageObj(int imageId) {
		super(imageId);

	}

	public ImageObj(String uId, int imageId, Set<String> tags, String date) {
		super(imageId);
		this.tags = tags;
		this.userId = uId;
		if (date != null) {
			StringTokenizer st = new StringTokenizer(date, " .:-");
			if (st.countTokens() >= 3) {
				String cleanDate = st.nextToken() + ":" + st.nextToken() + ":"
						+ st.nextToken();
				DateFormat sdf = new SimpleDateFormat("yy:MM:dd");
				Date d;
				try {
					this.time = sdf.parse(cleanDate);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

	public String toString() {
		String timeFormat = "no time";
		if(time!=null){
			Format format = new SimpleDateFormat("yyyy MM dd");
			timeFormat = format.format(time).toString();
		}
		String result = "\n--------------" + "\nTime [" + timeFormat
				+ "]\nEvent " + getEventTags().keySet() + "\nUser [" + userId
				+ "]\nConcepts " + getConcepts().keySet() + "\nPeople "
				+ getPeople().keySet();
		return result;
	}

	public String contentBasedName() {
		Format format = new SimpleDateFormat("yyyy MM dd");
		String timeFormat = format.format(time).toString();
		String result = "   -Time [" + timeFormat + "]   -Event "
				+ getEventTags().keySet() + "   -User [" + userId + "]   -Concepts "
				+ getConcepts().keySet();
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		return this.getDbId() == ((ImageObj) obj).getDbId();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

	public HashMap<String, Double> getPeople() {
		return people;
	}

	public void setPeople(HashMap<String, Double> people) {
		this.people = people;
	}

}
